package com.system.service.impl;

import com.system.mapper.SysUserMapper;
import com.system.model.SysUser;
import com.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 根据用户名和密码查询用户信息
     * @param sysUser
     * @return
     */
    @Override
    public SysUser querySysUserByUsernameAndPassword(SysUser sysUser) {
        SysUser sysUser_db = sysUserMapper.selectByUsernameAndPassword(sysUser);
        return sysUser_db;
    }

    /**
     * 根据用户名查询用户信息
     * @param sysUser
     * @return
     */
    @Override
    public SysUser querySysUserByUsername(SysUser sysUser) {
        SysUser sysUser_db = sysUserMapper.querySysUserByUsername(sysUser);
        return sysUser_db;
    }

    /**
     * 查询全部用户信息列表
     * @return
     */
    @Override
    public List<SysUser> queryAllSysUser() {
         List<SysUser> sysUserList = sysUserMapper.queryAllSysUser();
        return sysUserList;
    }

    /**
     * 添加用户信息
     * @param sysUser
     * @return
     */
    @Override
    public int sysUserAdd(SysUser sysUser) {
        int i = sysUserMapper.insertSelective(sysUser);
        return i;
    }

    /**
     * 删除用户信息
     * @param sysUserIdStr
     * @return
     */
    @Override
    public int sysUserDelete(String sysUserIdStr) {
        int i = sysUserMapper.deleteByPrimaryKey(Integer.parseInt(sysUserIdStr));
        return i;
    }

//修改UI，传输数据
    @Override
    public SysUser querySysUserByUserId(int user_id) {
        SysUser sysUser_db = sysUserMapper.selectByPrimaryKey(user_id);
        return sysUser_db;
    }

    /**
     * 修改用户信息
     * @param sysUser
     * @return
     */
    @Override
    public int sysUserUpdate(SysUser sysUser) {
        int i = sysUserMapper.updateByPrimaryKey(sysUser);
        return i;
    }
}
